package com.ybliang.plat.common.rpc.provider.executor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ThreadPoolExecutor;

@Configuration
public class ExecutorConfig {
	
	/**
	 * 设备环境切换重试线程池
	 * @return
	 */
	@Bean(name="rpcServiceHandlerExecutor")
    public ThreadPoolTaskExecutor RpcServiceHandlerExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); 
        executor.setThreadNamePrefix("rpcserver-exec");
        executor.setCorePoolSize(4);
        executor.setQueueCapacity(500);
        executor.setMaxPoolSize(6);
        //线程大于coreSize,多余线程数超过30s则销毁
        executor.setKeepAliveSeconds(30);
        // 设置拒绝策略,调用当前线程执行
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        executor.initialize();
        return executor;  
    }

}
